package com.daichi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daichi.entity.SysRole;
import com.daichi.entity.SysUserRole;
import com.daichi.mapper.SysRoleMapper;
import com.daichi.mapper.SysUserRoleMapper;
import com.daichi.service.SysUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Daichi Chou
 * @since 2021-06-05
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {

    private final SysRoleMapper sysRoleMapper;

    @Autowired
    public SysUserRoleServiceImpl(SysRoleMapper sysRoleMapper) {
        this.sysRoleMapper = sysRoleMapper;
    }

    @Override
    public List<SysRole> listRolesByUserId(Long id) {
        List<SysRole> sysRoles = sysRoleMapper.selectList(new QueryWrapper<SysRole>().inSql("id", "select role_id from sys_user_role where user_id = " + id));
        return sysRoles;
    }
}
